#include<bits/stdc++.h>
#define ll long long
using namespace std;
string s,t;
int n,m,dp[50005][1005],fail[1005],to[1005];
void init(){
	for(int i=2;i<=m;i++){
		fail[i]=fail[i-1];
		while(fail[i]&&t[fail[i]+1]!=t[i])fail[i]=fail[fail[i]];
		if(t[fail[i]+1]==t[i])fail[i]++;
	}
}
int main(){
	ios::sync_with_stdio(0);
  	freopen("neck.in","r",stdin);
  	freopen("neck.out","w",stdout);
	cin>>s>>t;
	n=s.size(),m=t.size();
	s=' '+s;
	t=' '+t;
	init();
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	for(int i=0;i<n;i++){
		to[0]=0;
		for(int j=0;j<m;j++){
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]+1);
			int u=to[fail[j]];
			if(s[i+1]==t[j+1])u=j;
			to[j]=u;
			if(s[i+1]==t[u+1])dp[i+1][u+1]=min(dp[i+1][u+1],dp[i][j]);
			else dp[i+1][0]=min(dp[i+1][0],dp[i][j]);
		}
	}
	int ans=INT_MAX;
	for(int i=0;i<m;i++)ans=min(ans,dp[n][i]);
	cout<<n-ans;
}
